/*
 * @Author: doing
 * @Date: 2023-08-20 21:08:16
 * @LastEditors: git config user.name && git config user.email
 * @LastEditTime: 2023-08-20 21:23:26
 * @FilePath: \线狮少年\src\directives\permission.js
 * @Description: 
 * 针对按钮级别的控制
 * Copyright (c) 2023 by 1540265624@qq.com, All Rights Reserved. 
 */
import store from "~/store"
function hasPermission(value,el = false){
    // console.log(value)
    if(!Array.isArray(value)){
        throw new Error(`需要配置权限，例如 v-permission="['getStatistics3,GET']"`)
    }
    const hasAuth = value.findIndex(v=>store.state.ruleNames.includes(v)) != -1
    if(el && !hasAuth){
        el.parentNode && el.parentNode.removeChild(el)
    }
    return hasAuth
}

export default {
    install(app){
        app.directive("permission",{
            mounted(el,binding){
                hasPermission(binding.value,el)
            }
        })
    }
}